package org.jobtask.schedule;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

public class ExceptionJobStack {
	
	private static Set<JobTask> stopJobStack=null;
	private static Set<JobTask> expStack=null;
//	private static HashMap<String,KeyValue> PIDStack=null;打算给linux下进程监控用,现在废弃掉
	
	static{
		stopJobStack=new HashSet<JobTask>();
		expStack=new HashSet<JobTask>();
//		PIDStack=new HashMap<String, KeyValue>();废弃
	}
	
	public synchronized static void addStopJob(JobTask job){
		stopJobStack.add(job);
	}
	
	public synchronized static void clearStopJob(){
		stopJobStack.clear();
	}
	
	public synchronized static boolean isEmpty(){
		return stopJobStack.isEmpty();
	}
	
	public synchronized static Object[] getJobs(){
		if(!expStack.isEmpty()){
			Set<JobTask> temp=new HashSet<JobTask>();
			for(Iterator<JobTask> iter=stopJobStack.iterator();iter.hasNext();){
				JobTask j=iter.next();
				if(expStack.contains(j)){
					expStack.remove(j);
				}else{
					temp.add(j);
				}
			}
			return temp.toArray();
		}else{
			return stopJobStack.toArray();
		}
	}
	
	public synchronized static void removeJob(JobTask job){
		if(stopJobStack.contains(job))
		       stopJobStack.remove(job);
		if(expStack.contains(job))
			  expStack.remove(job);
	} 
	
	public synchronized static void addExpJob(JobTask job){
		expStack.add(job);
	} 
	
	public static String getJobSize(){
		return "异常任务数: "+stopJobStack.size()+"过滤任务数: "+expStack.size();
	}
	
//	public static String getJobSize(){
//		return "expStack 的个数: "+expStack.size()+"stopJobStack的个数: "+stopJobStack.size();
//	}
	
//	public synchronized static Set getJobID(){
//		return PIDStack.keySet();
//	}
//	
//	public synchronized static KeyValue findPID(String jid){
//		return PIDStack.get(jid);
//	}
//	
//	public synchronized static void putPID(String jid,KeyValue pid){
//		PIDStack.put(jid,pid);
//	}
//	
//	public synchronized static void removePID(String jid){
//		PIDStack.remove(jid);
//	}
}
